<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电影票</title>
    <link type="text/css" rel="stylesheet" href="css/text.css"/>
</head>
<body>
    <div id="content">
    	<div class="title">发布电影</div>
        <div id="item">
            <label>电影名称</label><input type="text" v-model="mname">
        </div>
        <div id="item">
            <label>主演</label><input type="text" v-model="mart">
        </div>
        <div id="item" class="table">
            <label>类别</label>
            <select class="text2" @change="gradeChange($event)">
                <option v-for="(item,index) in types">{{item.tname}}</option>
            </select>
        </div>
        <div id="item">
            <label>导演</label><input type="text" v-model="mguide">
        </div>
        <div id="item">
            <label>价格</label><input type="text" v-model="mprice">
        </div>
        <div>
            <button class="button1"  @click="up">发布</button>
            <button class="button1"  @click="select">选择电影</button>
        </div>
    </div>
    
</body>
<script type="text/javascript" src="js/vue.js"></script>
<script type="text/javascript" src="js/axios.js"></script>
<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
<script type="text/javascript" src="js/qs.js"></script>
<script type="text/javascript">
let app = new Vue({
	el:"#content",
	data:{
		typeInfo:null,
		types:[],
		mname:null,
		mart:null,
		mguide:null,
		mprice:null,
		count:0
	},
	methods:{
		gradeChange:function(event){
			this.count+=1;
			console.log(event.target.value);
			this.typeInfo=event.target.value;
		},
		up:function(){
			if(this.mname == null || this.mart == null || this.mguide == null || this.mprice == null ){
				alert("请把信息填完整");
				return;
			}else{
				if(this.count==0){
					this.typeInfo=this.types[0].tname;
				}
				let params = new URLSearchParams();
				params.append("mname",this.mname);
				params.append("mart",this.mart);
				params.append("mguide",this.mguide);
				params.append("mprice",this.mprice);
				params.append("typeInfo",this.typeInfo);
				axios.post("up/uptext",params).then(rt =>{
					if(rt.data.code == 200){
						alert(rt.data.data);
					}else if(rt.data.code == 404){
						alert(rt.data.data);
					}else if(rt.data.code == 500){
						alert(rt.data.data);
					}else{
						alert("奇怪的错误");
					}
				})
			}
		},
		select: function(){
			location.href="index2.html";
		}
	},
	mounted:function(){
		console.log("start");
		axios.get("up/findType").then(rt =>{
			this.types=rt.data.data;
		})
	}
})
</script>
</html>